package com.xiaoxing.salesclient.mvp.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.utils.ArmsUtils;
import com.xiaoxing.salesclient.mvp.model.entity.UserCenter;
import com.xiaoxing.salesclient.mvp.model.entity.UserStaffCenter;

import java.util.List;

import xiaoxing.com.salesclient.R;


public class GeRenZhongXinDingDanJiLuUserStaffCenterAdapter extends BaseQuickAdapter<UserStaffCenter.DataBean.OrderBean, BaseViewHolder> {

    private Context mContext;
    private String mOrderStatus;
    private Pay mPay;

    public GeRenZhongXinDingDanJiLuUserStaffCenterAdapter(Context context, @Nullable List<UserStaffCenter.DataBean.OrderBean> data) {
        super(R.layout.item_ge_ren_zhong_xin_ding_dan_ji_lu, data);
        this.mContext = context;
    }

    public GeRenZhongXinDingDanJiLuUserStaffCenterAdapter(Context context, @Nullable List<UserStaffCenter.DataBean.OrderBean> data, Pay pay) {
        super(R.layout.item_ge_ren_zhong_xin_ding_dan_ji_lu, data);
        this.mContext = context;
        this.mPay = pay;
    }

    @Override
    protected void convert(BaseViewHolder helper, UserStaffCenter.DataBean.OrderBean item) {

        helper.setText(R.id.tv_shi_jian, ArmsUtils.stampToDate(item.getCreate_time()));
        helper.setText(R.id.tv_price, item.getProduct_price() + "元");
        helper.setText(R.id.tv_lei_xing, item.getProduct_name());
        helper.setText(R.id.tv_shu_liang, item.getProduct_num());

        TextView tvMyOrederStatus = helper.getView(R.id.tv_zhi_fu_zhuang_tai);
        if (item.getStatus().equals("0")) {
            mOrderStatus = "未付款";
            tvMyOrederStatus.setTextColor(Color.parseColor("#761e1c"));
            tvMyOrederStatus.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!TextUtils.isEmpty(item.getOrder_no()))
                        mPay.payOrder(item.getOrder_no());
                }
            });
        } else if (item.getStatus().equals("1")) {
            mOrderStatus = "已付款";
            tvMyOrederStatus.setTextColor(Color.parseColor("#88C283"));
            tvMyOrederStatus.setOnClickListener(null);

        } else if (item.getStatus().equals("2")) {
            mOrderStatus = "已取消";
            tvMyOrederStatus.setTextColor(Color.parseColor("#761e1c"));
            tvMyOrederStatus.setOnClickListener(null);
        }
        tvMyOrederStatus.setText(mOrderStatus);
    }

    public interface Pay {

        void payOrder(String order_no);
    }
}
